package co.com.jtune.view.componets;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;
import java.awt.RadialGradientPaint;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;

import javax.swing.JSlider;
import javax.swing.plaf.basic.BasicSliderUI;

public class VolumeJSliderUI extends BasicSliderUI {

	private static final Color[] THUMB_COLORS = {Color.decode("#CACBD6"), Color.decode("#FFFFFF"), Color.decode("#AEB2B6")};
    private static final float[] THUMB_FRACS = {0.2f, 0.6f, 0.8f};
    private static final int THUMB_DIAMETER = 18;
    
    private static final Color[] TRACK_COLOR = {Color.decode("#838484"), Color.decode("#9F9F9F"), Color.decode("#B0B0B0"), Color.decode("#CACBD6")};
    private static final float[] TRACK_FRACTIONS = {0.2f, 0.6f, 0.8f, 1f};
    private static final int TRACK_HEIGHT = 8;

    public VolumeJSliderUI(JSlider slider) {
        super(slider);
    }

    @Override
    public void paintTrack(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        Rectangle t = trackRect;
        
        int yPosition = (thumbRect.y + (THUMB_DIAMETER/2))-(TRACK_HEIGHT/2);
        
        Point2D start = new Point2D.Float(t.width/2, t.y);
        Point2D end = new Point2D.Float(t.width/2, (t.y + TRACK_HEIGHT));
        
        LinearGradientPaint gradientPaint = new LinearGradientPaint(start, end, TRACK_FRACTIONS, TRACK_COLOR);
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        
        g2d.setPaint(gradientPaint);
        g2d.fillRect(t.x, yPosition, t.width, TRACK_HEIGHT);
     
        
        g2d.fillOval(t.x-(TRACK_HEIGHT/2), yPosition, TRACK_HEIGHT, TRACK_HEIGHT);        
        g2d.fillOval((t.x + t.width -(TRACK_HEIGHT/2)), yPosition, TRACK_HEIGHT, TRACK_HEIGHT);
    }
    
    @Override
    protected Dimension getThumbSize() {
    	 Dimension size = new Dimension(THUMB_DIAMETER,THUMB_DIAMETER);
         return size;
    }

    @Override
    public void paintThumb(Graphics g) { 
        Graphics2D g2d = (Graphics2D) g;
        
        g2d.setRenderingHint(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        
        Rectangle t = thumbRect;
        
        Point2D center = new Point2D.Float(t.x+(THUMB_DIAMETER/2), t.y+(THUMB_DIAMETER/2));
        float radius = 25;      
        
        RadialGradientPaint gradientPaint = new RadialGradientPaint(center, radius, THUMB_FRACS, THUMB_COLORS);
        g2d.setPaint(gradientPaint);
        g2d.fillOval(t.x,t.y,THUMB_DIAMETER,THUMB_DIAMETER);
    }
}